<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
	xmlns:job="livcos.org/ns/process/job"
	xmlns:c="livcos.org/ns/cosmos"
  xmlns="http://www.w3.org/1999/xhtml"
  exclude-result-prefixes="c job">
  
  <xsl:import href="../style/meta_content.xsl"/>
  
  <xsl:output method="html"/>
  
  <xsl:template match="/">
    <html>
      <head>
        <title><xsl:value-of select="name(*)"/></title>
      	<meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>
        <style type="text/css">
          body {
            background-color: #FEFEFF;
            font-size: 80%;
            font-family: Verdana;
          }
          
          a {
            text-decoration: none;
          }
          
          .text {
            color: #008888;
          }
          
          .comment {
            color: gray;
          }
          
          .folding {
            background-color: #E8E8FF;
          }
          
          .root {
          
          }
          
          .row {
            margin-left: 4px;
            padding-left: 4px;
            border-left: medium;
            border-left-color: #E8E8FF;
            border-left-style: solid;
          }
          
          .elementName {
            color: #0000FF;
          }
          
          .emptyElementName {
          	color: #000066;
          }
          
          .attrName {
            color: #005588;
          }
          
          .attrVal {
            color: green;
          }
          
          .nsDecl {
          	color: gray;
          }
          
          .nsPrefix {
          	color: #A52A2A;
          }
          
          .nsUri {
          	color: #A52A2A;
          }
          
        </style>
        <script type="text/javascript"> 
          
          function Dom(id) {
            var e = document.getElementById(id);
            e.toggle = function() {
              if ((this.style.display == "inline") || (this.style.display == ""))
                this.style.display = "none";
              else                                    
                this.style.display = "inline";
            };
            return e;
          }
          
        </script>
      </head>
      <body>
      	<p>Job Protocol</p>
      	<xsl:apply-templates select="*[exception]" mode="title"/>
      	<xsl:apply-templates select="*"/>
      	<p>&#160;</p>
      </body>
    </html>
  </xsl:template>
  
	<xsl:template match="*" mode="content">
		<xsl:if test="../..">
			<xsl:attribute name="style">display:none</xsl:attribute>
		</xsl:if>
		<xsl:apply-templates select="node()"/>
	</xsl:template>
	
	<xsl:template match="parameter" mode="content">
		<xsl:attribute name="style">display:none</xsl:attribute>
		<xsl:apply-templates select="*">
			<xsl:sort select="name()"/>
		</xsl:apply-templates>
	</xsl:template>
	
	<xsl:template match="/*" mode="title">
		<xsl:apply-templates select="exception" mode="msg"/>
	</xsl:template>
	
	<xsl:template match="exception" mode="msg">
		<p>
			<xsl:for-each select="ancestor::exception">
				<xsl:text>- </xsl:text>        
			</xsl:for-each>
			<xsl:choose>
				<xsl:when test="message">
					<xsl:value-of select="message"/>
				</xsl:when>
				<xsl:otherwise>
					<xsl:value-of select="@type"/>
				</xsl:otherwise>
			</xsl:choose>
		</p>
		<xsl:apply-templates select="exception" mode="msg"/>
	</xsl:template>
	
	<xsl:template match="job:resolve/@uri" mode="attr_val">
		<xsl:variable name="uri">
			<xsl:choose>
				<xsl:when test="starts-with(., '/')"><xsl:value-of select="substring-after(., '/')"/></xsl:when>
				<xsl:otherwise><xsl:value-of select="."/></xsl:otherwise>
			</xsl:choose>
		</xsl:variable>
		<a class="attrVal" href="{$uri}"><xsl:value-of select="."/></a>
	</xsl:template>
	
	<xsl:template match="job:resolve/@obj" mode="attr_val">
		<a class="attrVal" href="livcos.org/web/admin/explore.view?objId={.}/.."><xsl:value-of select="."/></a>
	</xsl:template>
	
	<xsl:template match="job:transform/@def" mode="attr_val">
		<a class="attrVal" href="livcos.org/web/data{.}.html"><xsl:value-of select="."/></a>
	</xsl:template>
	
</xsl:stylesheet>
